package com.example.bookstore.mapper;

import com.example.bookstore.entity.Book;
import com.example.bookstore.entity.Category;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.util.List;

@Mapper
@Repository
public interface BookMapper {


    /**
     * 查找全部
     * @return
     */
    @Select("select * from book")
    List<Book> findAll();


    /**
     * 查找全部图书分类
     * @return
     */
    @Select("select * from category")
    List<Category> findAllCategory();


    /**
     * 根据id查找某本图书
     * @param id
     * @return
     */
    @Select("select * from book where id = #{id}")
    Book findById(Integer id);


    /**
     * 根据图书类型id查询该类型所有图书
     * @param cid
     * @return
     */
    @Select("select * from book where category_id = #{cid}")
    List<Book> findByCategory(Integer cid);

    /**
     * 添加图书
     * @param book
     * @return
     */
    @Insert("insert into book values (0,#{categoryId},#{name},#{image},#{description},#{price})")
    Integer add(Book book);


    /**
     * 根据关键词找书
     * @param bookName
     * @return
     */
    List<Book> findByKeyWord(String bookName);



}
